package com.yidu.hbatsams.action.AtsAttachment;

import com.yidu.hbatsams.dao.AtsSchemeAuditMapper;
import com.yidu.hbatsams.dao.AtsSchemeMapper;
import com.yidu.hbatsams.domain.*;
import com.yidu.hbatsams.domain.vo.UserVo;
import com.yidu.hbatsams.service.*;
import com.yidu.hbatsams.utils.Message;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("AtsAttachmentEmpAction")
@Controller
public class AtsAttachmentEmpAction {
    @Resource
    UserRoleService userRoleService;
    @Resource
    UserService userService;
    @Resource
    RoleService roleService;
    @Resource
    AtsAttachmentEmpService atsAttachmentEmpService;
    @Resource
    AtsAttachmentService atsAttachmentService;
    @Resource
    AtsSchemeAuditMapper atsSchemeAuditMapper;
    @RequestMapping("atsfindId")
    @ResponseBody
    public List<AtsAttachmentEmp> atsfindId(AtsAttachmentEmp atsAttachmentEmp){
        //返回对象
        return atsAttachmentEmpService.atsfindId(atsAttachmentEmp);
    }
    @RequestMapping("findUser")
    @ResponseBody
    public UserVo findUser(HttpSession session){
        //取到作用域中用户信息并创建一个对象接收
        UserVo user=(UserVo) session.getAttribute("user");
        //返回对象
        return user;
    }
    @RequestMapping("userIdupdate")
    @ResponseBody
    public Message userIdupdate(AtsAttachmentEmp atsAttachmentEmp,HttpSession session){
        //创建状态类
        Message mg=new Message();
        //以对象作为条件调用方法并定义变量接收
        int rows=atsAttachmentEmpService.userIdupdate(atsAttachmentEmp);
        //如果变量值大于零
        if(rows>0){
            //属性赋值数字成功
            mg.setNum(1);
            //属性赋值文字成功
            mg.setMsg("删除成功");
        }else{
            //属性赋值数字失败
            mg.setNum(0);
            //属性赋值文字失败
            mg.setMsg("删除失败");
        }
        //返回对象
        return mg;
    }
    @RequestMapping("updateLook")
    @ResponseBody
    public Message updateLook(AtsAttachmentEmp atsAttachmentEmp, HttpSession session, AtsAttachment atsAttachment){
        //属性艾低赋值作用域取的的艾低
        atsAttachmentEmp.setUserId(findUser(session).getUserId());
        //创建状态类
        Message mg=new Message();
        //以当前模型为条件调用修改方法并定义变量接收信息
        int rows=atsAttachmentEmpService.updateLook(atsAttachmentEmp);
        //如果变量大于零
        if(rows>0){
            //以当前模型作为条件调用修改方法
            atsAttachmentService.updateByPrimaryKeySelective(atsAttachment);
            //属性赋值数字状态成功
            mg.setNum(1);
            //属性赋值文字状态成功
            mg.setMsg("删除成功");
        }else{
            //属性赋值数字状态失败
            mg.setNum(0);
            //属性赋值文字状态失败
            mg.setMsg("删除失败");
        }
        //返回对象
        return mg;
    }
    @RequestMapping("selectAudit")
    @ResponseBody
    public Map<String,Object> selectAudit(String saId){
        //创建键值对储存对象
        Map<String,Object> map=new HashMap<>();
        //创建集合接收
        List<AtsSchemeAudit> atsSchemeAudit=atsSchemeAuditMapper.selectByPrimaryKeySaId(saId);
        //新增键值对
        map.put("msg","");
        //新增键值对
        map.put("code",0);
        //新增键值对
        map.put("data",atsSchemeAudit);
        //新增键值对
        map.put("count",atsSchemeAudit.size());
        //返回键值对象
        return map;
    }
}